﻿using System;
using System.Collections.Generic;
using System.Web.Services;
using Monkey.Warrenty.Biz;

namespace MonkeyWarranty.Web.WarrantyTickets
{
    public partial class ReceivedProducts : System.Web.UI.Page
    {
        #region Properties

        private static WarrantyProductBiz _warrantyProductBiz;

        private static WarrantyProductBiz WarrantyProductManager
        {
            get { return _warrantyProductBiz ?? (_warrantyProductBiz = new WarrantyProductBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod(EnableSession = true)]
        public static object ProductList(int jtStartIndex, int jtPageSize, string jtSorting, string name, string code, string ticketCode)
        {
            var ticketCount = WarrantyProductManager.GetReceivedWarrantyProductsCountByFilter(name, code, ticketCode);
            var products = WarrantyProductManager.GetReceivedWarrantyProductsByFilter(jtStartIndex, jtPageSize, jtSorting, name, code, ticketCode);
            foreach (var product in products)
            {
                // product.CreatedTimeString = string.Format("{0:HH:mm}", product.CreatedDate);
                switch (product.ReceivedFrom)
                {
                    case 1:
                        product.ReceivedFromName = Resources.GlobalStrings.Customers;
                        break;
                    case 2:
                        product.ReceivedFromName = Resources.GlobalStrings.Employees;
                        product.DealerEmployeeName = product.FromEmployeeName;
                        break;
                    case 3:
                        product.ReceivedFromName = Resources.GlobalStrings.Dealers;
                        product.DealerEmployeeName = product.FromDealerName;
                        break;
                }
            }
            return new { Result = "OK", Records = products, TotalRecordCount = ticketCount };
        }

        [WebMethod(EnableSession = true)]
        public static object SendBackCustomer(List<long> productIds)
        {
            WarrantyProductManager.SendBackCustomer(productIds);
            return new { Result = "OK" };
        }
    }
}